package com.example.prison.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.prison.entity.AreaManagement;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
* @author jiang
* @description 针对表【area_management】的数据库操作Mapper
* @createDate 2023-05-26 17:15:28
* @Entity com.example.prison.entity.AreaManagementVO
*/
@Mapper
public interface AreaManagementMapper extends BaseMapper<AreaManagement> {

    @Select("select * from area_management a where a.defense_section is not null order by a.id desc")
    List<AreaManagement> get();

    @Select("select * from area_management a order by a.id desc")
    List<AreaManagement> getAll();

    @Select("select * from area_management a where a.sentry_post is not null order by a.id desc")
    List<AreaManagement> getSentryPost();

    @Insert("insert into area_management(defense_section, defense_section_point,defense_address, sentry_post, sentry_address, time, alarm_level, status, " +
            "voltage1,status1,voltage2,status2,battery_voltage,battery_t,air,in_voltage,gateway_address,gateway_port,module_address, " +
            "alarm_status, device_number, detection) " +
            "values (#{defenseSection}, #{defenseSectionPoint}, #{defenseAddress}, #{sentryPost}, #{sentryAddress}, #{time}, #{alarmLevel}, #{status}, " +
            "#{voltage1},#{status1},#{voltage2},#{status2},#{batteryVoltage},#{batteryT},#{air},#{inVoltage},#{gatewayAddress},#{gatewayPort},#{moduleAddress}, " +
            "#{alarmStatus}, #{deviceNumber}, #{detection})")
    int add(AreaManagement area);

    @Update("update area_management set defense_section=#{area.defenseSection}, defense_section_point=#{area.defenseSectionPoint}, defense_address=#{area.defenseAddress}, sentry_post=#{area.sentryPost}, sentry_address=#{area.sentryAddress}, time=#{area.time}, alarm_level=#{area.alarmLevel}, status=#{area.status}, " +
            "voltage1=#{area.voltage1},status1=#{area.status1}, voltage2=#{area.voltage2}, status2=#{area.status2},battery_voltage=#{area.batteryVoltage},battery_t=#{area.batteryT},air=#{area.air},in_voltage=#{area.inVoltage},gateway_address=#{area.gatewayAddress},gateway_port=#{area.gatewayPort},module_address=#{area.moduleAddress}, " +
            "alarm_status=#{area.alarmStatus}, device_number=#{area.deviceNumber}, detection=#{area.detection} where id = #{id}")
    int updateArea(AreaManagement area,Integer id);

    @Update("update area_management set defense_section=#{area.defenseSection}, defense_section_point=#{area.defenseSectionPoint}, " +
            "defense_address=#{area.defenseAddress}, sentry_post=#{area.sentryPost}, sentry_address=#{area.sentryAddress}, " +
            "device_number=#{area.deviceNumber}, detection=#{area.detection},module_address=#{area.moduleAddress} where id = #{id}")
    int updateAreaName(AreaManagement area,Integer id);

    @Update("update area_management set  time=#{area.time}, alarm_level=#{area.alarmLevel}, status=#{area.status}, " +
            "voltage1=#{area.voltage1},status1=#{area.status1}, voltage2=#{area.voltage2}, status2=#{area.status2}," +
            "battery_voltage=#{area.batteryVoltage},battery_t=#{area.batteryT},air=#{area.air},in_voltage=#{area.inVoltage}, " +
            "alarm_status=#{area.alarmStatus} where id = #{id}")
    int updateAreaVol(AreaManagement area, Integer id);

    @Update("update area_management set defense_section=#{area.defenseSection}, defense_section_point=#{area.defenseSectionPoint}, defense_address=#{area.defenseAddress}, sentry_post=#{area.sentryPost}, sentry_address=#{area.sentryAddress}, time=#{area.time}, alarm_level=#{area.alarmLevel}, status=#{area.status}, " +
            "voltage1=#{area.voltage1},status1=#{area.status1}, voltage2=#{area.voltage2}, status2=#{area.status2},battery_voltage=#{area.batteryVoltage},battery_t=#{area.batteryT},air=#{area.air},in_voltage=#{area.inVoltage},gateway_address=#{area.gatewayAddress},gateway_port=#{area.gatewayPort},module_address=#{area.moduleAddress}, " +
            "alarm_status=#{area.alarmStatus}, device_number=#{area.deviceNumber}, detection=#{area.detection} where id = #{id}")
    int updateAreaFail(AreaManagement area,Integer id);

    @Delete("<script>delete from area_management where id in <foreach collection=\"ids\" item=\"item\" open=\"(\" separator=\",\" close=\")\">#{item} </foreach> </script>")
    void deleteArea(@Param("ids") Integer[] ids);

    @Delete("delete from area_management where id=#{id}")
    void deleteOneById(@Param("id") Integer id);

    @Delete("delete from area_management")
    void deleteAll();

    @Delete("delete from area_management where defense_section = #{defenseSection}")
    void deleteAreaBySection(@Param("defenseSection") String defenseSection);

    @Select("select * from area_management where id=#{id}")
    AreaManagement getById(@Param("id") Integer id);

    @Select("select * from area_management where id=#{id} order by id desc")
    AreaManagement getAreaById(@Param("id") Integer id);

    @Select("select * from area_management a where a.defense_section like concat('%',#{defenseSection},'%') order by a.id desc")
    List<AreaManagement> getBySection(@Param("defenseSection") String defenseSection);

    @Select("select * from area_management a where a.defense_section=#{defenseSection}")
    AreaManagement getOneByDefenseSection(@Param("defenseSection") String defenseSection);

    @Select("select * from area_management a where a.defense_section=#{defenseSection}")
    List<AreaManagement> getByDefenseSection(@Param("defenseSection") String defenseSection);

    @Select("select * from area_management a where a.defense_section_point like concat('%',#{defenseSectionPoint},'%') order by a.id desc")
    List<AreaManagement> getByPoint(@Param("defenseSectionPoint") String defenseSectionPoint);

    @Select("select * from area_management a where a.defense_section like concat('%',#{defenseSection},'%') and a.defense_section_point like concat('%',#{defenseSectionPoint},'%') order by a.id desc")
    List<AreaManagement> getLinkBySectionAndPoint(@Param("defenseSection") String defenseSection, @Param("defenseSectionPoint") String defenseSectionPoint);

    @Select("select * from area_management a where a.defense_section=#{defenseSection} and a.defense_section_point=#{defenseSectionPoint} order by a.id desc")
    List<AreaManagement> getBySectionAndPoint(@Param("defenseSection") String defenseSection, @Param("defenseSectionPoint") String defenseSectionPoint);

    @Select("select * from area_management a where a.sentry_post like concat('%',#{sentryPost},'%') order by a.id desc")
    List<AreaManagement> getBySentryPost(@Param("sentryPost") String sentryPost);

    @Select("select * from area_management a where a.sentry_post=#{sentryPost}")
    AreaManagement getOneBySentryPost(@Param("sentryPost") String sentryPost);

    @Select("select * from area_management where alarm_status = #{alarmStatus} order by id desc")
    List<AreaManagement> getByStatus(@Param("alarmStatus") String alarmStatus);




    @Select("select * from area_management a where a.is_mark='未标记'")
    List<AreaManagement> getUnmarkArea();

    @Update("update area_management set is_mark='已标记',mark_id=#{MarkId} where defense_section=#{defenseSection} ")
    void setMark(@Param("defenseSection") String defenseSection, @Param("MarkId") String MarkId);

    @Update("update area_management set is_mark='未标记' where defense_section=#{defenseSection} ")
    void setUnMark(@Param("defenseSection") String defenseSection);

    @Update("update area_management set gateway_address=#{ip},gateway_port=#{port}")
    int updateIPAndPort(@Param("ip")String ip, @Param("port")Integer port);

    @Update("update area_management set setting=#{setting} where module_address=#{moduleAddress}")
    int updateSetting(@Param("setting")String setting, @Param("moduleAddress")String moduleAddress);


}




